package a.oschina.eventbusdemo.test;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import org.greenrobot.eventbus.EventBus;

import java.util.concurrent.TimeUnit;

import a.oschina.eventbusdemo.MessageEvent;
import a.oschina.eventbusdemo.R;

public class SecondActivity extends AppCompatActivity {

//    private Handler handler = new Handler() {
//        @Override
//        public void handleMessage(Message msg) {
//            if (msg.what == 1) {
//                Intent intent = getIntent();
//                intent.putExtra("content", "Hello World From Network");
//                setResult(0, intent);
//                finish();
//            }
//        }
//    };


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_b);
//
//        MessageEvent messageEvent = new MessageEvent();
//        messageEvent.setMessage("Hello World From Network");
//        EventBus.getDefault().post(messageEvent);
//        Log.i("TAG", "Activity B");
//        finish();



        new Thread(new Runnable() {
            @Override
            public void run() {

                //模拟网络任务
                try {
                    TimeUnit.SECONDS.sleep(2);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
             //   handler.sendEmptyMessage(1);

                MessageEvent messageEvent = new MessageEvent();
                messageEvent.setMessage("Hello World From Network");
                EventBus.getDefault().post(messageEvent);
                  Log.i("TAG", "Activity B");
                finish();

            }
        }).start();




    }
}
